<?php 
//$dic = directory_map('./plugin',1);
$dic = directory_map(APPPATH.'/modules',1);

?>
<style type="text/css">
	a.btnDelete img{display:none}
</style>
<div class="box_type02">
	<h2 class="txt">컨텐츠관리</h2>
	<p class="icon"><a href="javascript:void(0);" class="icon_m04">매뉴얼</a></p>

	<div class="contCont">
	
		<ul class="c_box">
			<li class="left">
				<div id="contsMenu">
					<div class="addPlus">
					 <input type="text" id="" name="" class="ip" value="상위메뉴추가" /> 
                      <input type="button" id="add_folder" class="btn_search" title="검색" value="" /> 
					</div>
					<div id="demo" class="demo mt10" style="background:#fff"></div>
				</div>
			</li>
			<li class="right">
				<!--[s] 쓰기 -->
				<form name="frmReg" method="post" action="/contents/contentsForm/contents_plugin">
				<input type="hidden" name="id" value="<?=$id?>">
				<input type="hidden" name="dbjob" value="<?php echo $dbjob?>">
				<fieldset class="board_write">
					<legend>컨텐츠관리</legend>
					<table cellspacing="0" summary="컨텐츠관리">
						<caption>컨텐츠관리</caption>
						<tr>
							<th scope="row" width="100"><p class="point">기능선택</p></th>
							<td>
								<div>
									
									<ul class="w20 c_box">
									<?php
										foreach($this->config->item('ch_contents') as $key => $value){
											$checked = ($key == 'PLUGIN') ? 'checked' : '';
											echo "<li><input type=\"radio\" id=\"types{$key}\" name=\"page_type\" class=\"ip_c\" value=\"{$key}\" {$checked} /><label for=\"types{$key}\" class=\"txt_type01\">{$value}</label></li>\n";
										}
									?>
									<!--</ul>  -->
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">제목</p></th>
							<td>
								<div><input type="text" id="" name="title" class="ip_i" style="width:481px;" value="<?php echo $title?>"/></div>
							</td>
						</tr>
						
				
						
						<tr>
							<th scope="row"><p class="point">키워드</p></th>
							<td>
								<div><input type="text" id="" name="keyword" class="ip_i" style="width:481px;" value="<?php echo $keyword?>" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">설명</p></th>
							<td>
								<div><input type="text" id="" name="description" class="ip_i" style="width:481px;" value="<?php echo $description?>" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">플러그인	</p></th>
							<td>
								<div>
								
								<select name="plugin" class="ip_s" style="width:300px;">
								<?php 
									foreach($dic as $item){
										$xml = read_file(APPPATH.'/modules/'.$item.'/module.xml');
										if($xml){
											$parser = new XMLParser($xml);
											$parser->Parse();
											$plugin = '{"module_name" : "'.$item.'","controller":"'.$parser->document->controller[0]->tagData.'","function":"'.$parser->document->function[0]->tagData.'"}' ;
											echo "<option value='{$plugin}'>{$parser->document->title[0]->tagData}</option>\n";
										}
									}
								?>	
								</select>
								</div>
							</td>
						</tr>
					</table>
				</fieldset>
				</form>
				<!--[e] 쓰기 -->
			</li>
		</ul>

	</div>

	<!-- [s] 버튼 -->
	<ul class="botton_box mt30">
		<li class="center">
			<a href="javascript:frmValid();" class="btnAdd"><img src="/theme/<?=$_theme?>/images/common/btn_ok.gif" alt="확인" /></a>
			<!-- <a href="javascript:void(0);"><img src="/theme/<?=$_theme?>/images/common/btn_modify.gif" alt="수정" /></a> -->
			<a href="javascript:frmDelete();" class="btnDelete"><img src="/theme/<?=$_theme?>/images/common/btn_delete.gif" alt="삭제" /></a>
			<!-- <a href="javascript:void(0);"><img src="/theme/<?=$_theme?>/images/common/btn_cancel.gif" alt="취소" /></a> -->
		</li>
	</ul>
	<!-- [e] 버튼 -->

	<!--[s] Tip -->
	<dl id="tip" class="mt30">
		<dt>Tip</dt>
		<dd>인터넷익스플로러의 '호환성보기' 기능을 사용중인 접속자에게 자동으로 최신버전 기준으로 사이트를 출력하도록 처리합니다.</dd>
		<dd>코딩방식에 따라 특정 버전의 브라우저에서 사이트가 깨질수 있으니, 충분한 테스트 후 기능을 설정해 주시기 바랍니다.</dd>
	</dl>
	<!--[e] Tip -->
</div>
<script type="text/javascript" src="/common/js/contents.js"></script>
<script type="text/javascript">
//<![CDATA[
function setMenu(){
	with(document.frmMenu){
		if(!menu_nm.value){
			alert("메뉴명을 입력해주세요");
			return;
		}
	}	

	$.ajax({
		type: "POST",
		url: "/chmanager/ajax_menu",
		data: $("[name=frmMenu]").serialize(),
		success: function(data){
			alert(data);
			
		},
		error:function(error){
			alert('에러');
		}
	});
}

function frmValid(){
	with(document.frmReg){
		$("[name=page_type]").attr("disabled",false);
		submit();
	}
}

$(function () {
	var uri_template = {"HTML":"/chmanager/contents/contents_html","BOARD":"/chmanager/contents/contents_board","GALLERY":"/chmanager/contents/contents_gallery","PLUGIN":"/chmanager/contents/contents_plugin"};
	$("[name=page_type]").click(function(){
		var contents_template= uri_template[$(this).val()];
		location.href = contents_template+'/id/'+$("[name=id]").val();
	});

		
	if($("[name=dbjob]").val() == 'u'){ 
		$("[name=page_type]").attr("disabled",true);
		
		$("a.btnDelete img").show();
	}

	if($("[name=id]").val()) $(".btnAdd").show();
	
	
});
//]]>							
</script>